package exp.day05;

import java.util.*;

/*小云和朋友们去爬香山，为美丽的景色所陶醉，想合影留念。如果他们站成一排
 * 男生全部在左（从拍照者的角度）并按照从矮到高的顺序从左到右排，女生全部在右
 * 并按照从高到矮的顺序从左到右排，请问他们合影的效果是什么样的（所有人的身高都不同）？
 * 输入：6
 * male 1.72
 * male 1.78
 * female 1.61
 * male 1.65
 * female 1.70
 * female 1.56
 *
 * 输出：1.65 1.72 1.78 1.70 1.61 1.56
 */
public class Exp01GroupPhoto {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        Map<String, String> contacts = new HashMap<>();
        Set<String> S1 = new TreeSet<>();
        Set<String> S2 = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int x = o2.toString().compareTo(o1.toString());
                return x;
            }
        });
        StringBuffer sb = new StringBuffer();
        int n = cin.nextInt();
        cin.nextLine();         //吸收回车
        for (int i = 0; i < n; i++) {
            String str = cin.nextLine();
            String[] a = str.trim().split("\\s+");
            contacts.put(a[0], a[1]);
            if (a[0].equals("male")) {
                S1.add(contacts.get("male"));
                continue;
            } else if (a[0].equals("female")) {
                S2.add(contacts.get("female"));
                continue;
            } else {
                System.err.println("input error!");
            }
        }
        for (String i : S1)
            System.out.print(i + " ");
        for (String i : S2)
            System.out.print(i + " ");

    }
}
